package queue;

import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class MyQueue {
    class ListNode{
        public int val;
        public ListNode next;
        public ListNode prev;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode frist = null;
    public ListNode last = null;
    public int size = 0;

    public void offer (int val){
        ListNode node = new ListNode(val);
        if(frist == null){
           last = frist = node;
        }else{
            last.next = node;
            node.prev = last;
            last = node;
        }
        size++;
    }

    public int poll (){
        if(isEmpty()){
            return -1;
        }
        int ret = frist.val;
        frist = frist.next;
        if(frist != null) {
            frist.prev = null;
        }
        size--;
        return ret;
    }

    public int peek (){
        if(isEmpty()){
            return -1;
        }else{
            return frist.val;
        }
    }

    public boolean isEmpty(){
        if(size == 0){
            return true;
        }else{
            return false;
        }
    }
}
